package homework1;

public class homework1_rework {

	public static void main(String args[]){
	
		int SingleNumbers[] = new int[]{10};
		
		System.out.println("Single Number: " + isOrdered(SingleNumbers));
		
		int OrderedNumbers[] = new int[]{0,0,0,10,20,20,30};
		
		System.out.println("Ordered Numbers: " + isOrdered(OrderedNumbers));
		
		int RandomNumbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};
		
		System.out.println("Non-ordered, Random Numbers: " + isOrdered(RandomNumbers));

		int DuplicateNumbers[] = new int[]{0,0,0,10,10,14,15,16,17,17,900,900,102020};
		
		System.out.println("Ordered, but Duplicate Numbers: " + isOrdered(DuplicateNumbers));

		int OutatStartNumbers[] = new int[]{40,2,3,4,5,6,7,8};
		
		System.out.println("Out of Order at Start: " + isOrdered(OutatStartNumbers));
		
		int OutatFinishNumbers[] = new int[]{0,2,3,4,5,6,7,8,0};
		
		System.out.println("Out of Order at Finish: " + isOrdered(OutatFinishNumbers));

		int OutatMiddleNumbers[] = new int[]{0,2,3,2,5,6,7,8,9};
		
		System.out.println("Out of Order at Middle: " + isOrdered(OutatMiddleNumbers));

		int NullNumbers[] = null;
		
		System.out.println("Null Array: " + isOrdered(NullNumbers));

		int EmptyNumbers[] = new int[0];
		
		System.out.println("Empty Array: " + isOrdered(EmptyNumbers));
		
	}
	
	/**
	 * @param X an int array of any length (including empty)
	 * @return true if the elements in X are in order of non-decreasing (rising) values
	 */
	public static boolean isOrdered(int[] X) {
		
		if (X == null) return true;
		
		int previous = Integer.MIN_VALUE;
		
		for(int current: X){
			
			if (previous > current) return false;
			
			previous = current;
		}
		
		return true;
		
		
	}

}
